#!/usr/bin/env bash
set -euvo pipefail

CI_COMPOSE_FILE=$1
WORKSPACE_DIR=/tmp/job-workspace

# Optional - only used for print_colorized
source anchore-ci/utils

print_colorized INFO "Running Anchore Engine functional tests."; echo

print_colorized WARN "TOX_ENV: ${TOX_ENV}"; echo

default_tox_envs="py36"
tox_env="${TOX_ENV:-$default_tox_envs}"

for e in $(echo "${tox_env}"); do
    docker-compose -f ${CI_COMPOSE_FILE} exec job-runner bash -c "\
        set -x && \
        anchore-cli --u admin --p foobar --url http://engine-api:8228/v1 system wait --feedsready '' && \
        anchore-cli --u admin --p foobar --url http://engine-api:8228/v1 system status && \
        /home/anchore/.local/bin/tox -e '${e}' tests/functional --result-json .tox/test-reports.log ;\
        "
done

print_colorized INFO "Finished running Anchore Engine functional tests."; echo
